from django.db import models
from django.utils import timezone

from books.models import User, Books


# Create your models here.
class BorrowCart(models.Model):
    user = models.ForeignKey(User,on_delete=models.CASCADE)
    book = models.ForeignKey(Books,on_delete=models.CASCADE)
    starttime = models.DateTimeField(default=timezone.now)
    endtime = models.DateTimeField()
    def save(self, *args, **kwargs):
        if not self.id:
            self.endtime = self.starttime + timezone.timedelta(days=2)
        super(BorrowCart, self).save(*args, **kwargs)

    class Meta:
        db_table='cart'
    def __str__(self):
        return self.user



